//
//  GQHTruckModel.m
//  Xanthium
//
//  Created by GuanQinghao on 27/03/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#import "GQHTruckModel.h"


@implementation GQHTruckModel

+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
    
    return @{
             @"qh_truckID" : @"id",
             @"qh_postTime" : @"sendDatetime",
             @"qh_state" : @"state",
             @"qh_driverID" : @"userId",
             @"qh_driverName" : @[@"userName",@"name"],
             @"qh_driverAvatar" : @"headPortrait",
             @"qh_driverMobile" : @"phone",
             @"qh_driverScore" : @[@"score",@"avgScore"],
             @"qh_departureID" : @"originId",
             @"qh_departure" : @"originId",
             @"qh_destinationID" : @"destinationId",
             @"qh_destination" : @"destinationId",
             @"qh_followed" : @"friend",
             @"qh_note" : @"note",
             @"qh_modelCode" : @"vehicleclassificationcode",
             @"qh_model" : @"vehicleclassificationcode",
             @"qh_normalLength" : @"carLength",
             @"qh_normalLoading" : @"carLoad",
             @"qh_licensePlateNumber" : @"licPlateNum",
             @"qh_truckImages" : @"carPhoto",
             @"qh_freightTypeID":@"canCarryGoods",
             @"qh_freightType" : @"canCarryGoods",
             @"qh_loadable" : @"canCarryTonnage",
             @"qh_inspectTime" : @"auditTime",
             @"qh_inspectState" : @"auditState",
             @"qh_inspector" : @"auditor",
             @"qh_routeModelArray" : @"buFocusOnLineVOs",
             @"qh_commentModelArray" : @"buAssessmentVOs",
             @"qh_free" : @"empty"
             };
}

+ (nullable NSDictionary<NSString *, id> *)modelContainerPropertyGenericClass {
    
    return @{
             @"qh_routeModelArray" : GQHRouteModel.class,
             @"qh_commentModelArray" : GQHCommentModel.class
             };
}

///  获取空车列表
+ (void)qh_fetchFreeTrucksWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHTruckModel *> *trucks))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buEmpty/1/list"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *truckArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHTruckModel *truckModel = [GQHTruckModel yy_modelWithDictionary:object];
                if (truckModel) {
                    
                    [truckArray addObject:truckModel];
                }
            }
            success(YES,code,message,truckArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

+ (void)qh_fetchDeleteMyEmptyCarsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHTruckModel *> *trucks))success failure:(void(^)(NSError *error))failure
{
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buEmpty/1/delete"];
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        if (0 == [code integerValue])
        {
            success(YES,code,message,@[]);
        }
        else
        {
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

//获取我的空车
+ (void)qh_fetchGetMyEmptyCarsWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHTruckModel *> *trucks))success failure:(void(^)(NSError *error))failure
{
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buEmpty/1/list"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *truckArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHTruckModel *truckModel = [GQHTruckModel yy_modelWithDictionary:object];
                if (truckModel) {
                    
                    [truckArray addObject:truckModel];
                }
            }
            success(YES,code,message,truckArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

/// 获取熟车列表
+ (void)qh_fetchFollowedTrucksWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, NSArray<GQHTruckModel *> *trucks))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buUsersAttention/1/myDrivers"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            NSMutableArray *truckArray = [NSMutableArray array];
            for (NSDictionary *object in [data objectForKey:@"list"]) {
                
                GQHTruckModel *truckModel = [GQHTruckModel yy_modelWithDictionary:object];
                if (truckModel) {
                    
                    [truckArray addObject:truckModel];
                }
            }
            success(YES,code,message,truckArray);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

/// 获取空车详情
+ (void)qh_fetchFreeTruckInfoWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, GQHTruckModel *truck))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buEmpty/1/findOne"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            GQHTruckModel *truckModel = [GQHTruckModel yy_modelWithDictionary:data];
            
            success(YES,code,message,truckModel);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

/// 获取关注的车辆详情
+ (void)qh_fetchFollowedTruckInfoWithParameters:(NSDictionary *)parameters success:(void(^)(BOOL status, NSNumber *code, NSString *message, GQHTruckModel *truck))success failure:(void(^)(NSError *error))failure {
    
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buUsersAttention/1/carDetail"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:parameters success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        DLog(@"%@---%@---%@",code,message,data);
        
        if (0 == [code integerValue]) {
            
            GQHTruckModel *truckModel = [GQHTruckModel yy_modelWithDictionary:data];
            
            success(YES,code,message,truckModel);
        } else {
            
            success(NO,code,message,nil);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

@end
